package com;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.StringTokenizer;

public class AmazonCSVParser {

	public ArrayList parseCSV(String file) {
		int skipCount = 1;
		try {
			String line;
			BufferedReader br = new BufferedReader(new FileReader(file));
			int i = 0;
			while ((line = br.readLine()) != null) {
				i++;
				if (i <= skipCount)
					continue;

				// String
				StringTokenizer st1 = new StringTokenizer(line, "\t", false);

				Hashtable tables = new Hashtable();
				int tokenCount = 0;
				while (st1.hasMoreTokens()) {
					String token = st1.nextToken();
					tokenCount++;

					System.out.println(token);

				}

			}
		} catch (FileNotFoundException e) {

			e.printStackTrace();

		} catch (IOException e) {

			e.printStackTrace();

		}

		return null;
	}

	public void constructBean(Hashtable tables, int tokenCount, String token) {
		ResPartnerAddress contactaddress, deliveryaddress = null;
		ResPartner resPartner = null;
		if (tables.get(ResPartner.class.getName()) == null) {
			resPartner = new ResPartner();
			tables.put(ResPartner.class.getName(), resPartner);
		}

		if (tables.get("contactaddress") == null) {
			contactaddress = new ResPartnerAddress();
			tables.put("contactaddress", contactaddress);
		}

		if (tables.get("deliveryaddress") == null) {
			deliveryaddress = new ResPartnerAddress();
			tables.put("deliveryaddress", deliveryaddress);
		}

		resPartner = (ResPartner) tables.get(ResPartner.class.getName());
		contactaddress = (ResPartnerAddress) tables.get("contactaddress");
		deliveryaddress = (ResPartnerAddress) tables.get("deliveryaddress");

		switch (tokenCount) {
		case 1:
			break;

		case 2:
			break;

		case 3:
			break;

		case 4:
			break;

		case 5:
			contactaddress.setType("default");
			contactaddress.setEmail(token);
			break;

		case 6:
			contactaddress.setName(token);
			break;

		case 7:
			break;

		case 8:
			break;

		case 9:
			break;

		case 10:
			break;

		case 11:
			break;

		case 12:
			break;

		case 13:
			break;

		case 14:
			break;

		case 15:
			break;

		case 16:
			break;

		case 17:
			break;

		case 18:
			break;

		case 19:
			break;

		case 20:
			break;

		case 21:
			break;

		case 22:
			break;

		case 23:

			break;

		case 24:

			break;

		case 25:
			break;
		}

	}

}
